package tests;

import static org.junit.Assert.*;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;

import org.junit.Test;
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;

import pdi.OpenCvCaller;
import pdi.core.Image;

import de.bwaldvogel.liblinear.Feature;
import de.bwaldvogel.liblinear.FeatureNode;
import de.bwaldvogel.liblinear.Linear;
import de.bwaldvogel.liblinear.Model;
import de.bwaldvogel.liblinear.Parameter;
import de.bwaldvogel.liblinear.Problem;
import de.bwaldvogel.liblinear.SolverType;

public class LibsIntegrationTest {

	@Test
	public void openCVTest() {

		System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
		Mat mat = Mat.eye( 3, 3, CvType.CV_8UC1 );
		System.out.println( "mat = " + mat.dump() );
	}
	
	@Test
	public void liblinearTest(){
		
		Problem problem = new Problem();
		problem.l = 2;// number of training examples
		problem.n = 2; // number of features
		problem.x = new FeatureNode[][]{ {new FeatureNode(1, 1), new FeatureNode(2, 2)}, {new FeatureNode(1, 3), new FeatureNode(2, 4)}}; // feature nodes
		problem.y = new double[]{1,-1}; // target values

		SolverType solver = SolverType.L2R_LR; // -s 0
		double C = 1.0;    // cost of constraints violation
		double eps = 0.01; // stopping criteria

		Parameter parameter = new Parameter(solver, C, eps);
		Model model = Linear.train(problem, parameter);
		
		Feature[] instance = { new FeatureNode(1, 1), new FeatureNode(2, 2) };
		double prediction = Linear.predict(model, instance);
		
		System.out.println(prediction);
	}
	
	

}
